/*
 * utils.h
 *
 *  Created on: 10.06.2012
 *      Author: sebastian
 *
 *  Modified on: 19.06.2012
 *  	Author: drako
 */

#ifndef MMUTILS_H_
#define MMUTILS_H_

#include <string>
#include <sstream>
#include <typeinfo>

namespace mbge
{
	namespace detail
	{
		template <typename TargetType, typename SourceType>
		struct lexical_cast_helper;

		// cast from string
		template <typename TargetType>
		struct lexical_cast_helper<TargetType, std::string>
		{
			static TargetType convert(std::string const & src)
			{
				std::istringstream strm(src);
				TargetType result;
				if (!(strm >> result))
					throw std::bad_cast();
				return result;
			}
		};

		// cast to string
		template <typename SourceType>
		struct lexical_cast_helper<std::string, SourceType>
		{
			static std::string convert(SourceType const & src)
			{
				std::ostringstream strm;
				if (!(strm << src))
					throw std::bad_cast();
				return strm.str();
			}
		};
	}

	// made a better casting function
	template <typename TargetType, typename SourceType>
	TargetType lexical_cast(SourceType const & src)
	{
		return detail::lexical_cast_helper<TargetType, SourceType>::convert(src);
	}
}

enum LogType {
	LT_NORMAL,
	LT_ERROR
};

void mLog(std::string const & msg, LogType l = LT_NORMAL);


#endif
